package com.yxx.mapper;

import com.github.pagehelper.Page;
import com.yxx.annotation.AutoFill;
import com.yxx.medicinecommon.enumeration.OperationType;
import com.yxx.medicinepojo.dto.ChineseMedicinePageQueryDTO;
import com.yxx.medicinepojo.dto.WesternMedicineDTO;
import com.yxx.medicinepojo.dto.WesternMedicinePageQueryDTO;
import com.yxx.medicinepojo.entity.ChineseMedicine;
import com.yxx.medicinepojo.entity.ChineseWesternMedicine;
import com.yxx.medicinepojo.entity.WesternMedicine;
import com.yxx.medicinepojo.vo.ChineseMedicineVO;
import com.yxx.medicinepojo.vo.WesternMedicineVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author yuxiangxun
 * @date 2024/9/21
 * @apiNote
 */
@Mapper
public interface WesternMedicineMapper {

    /**
     * 西药分页查询
     * @param westernMedicinePageQueryDTO
     * @return
     */
    Page<WesternMedicineVO> pageQueryWesternMedicine(WesternMedicinePageQueryDTO westernMedicinePageQueryDTO);

    /**
     * 根据分类id查询西药
     * @param westernMedicineVO
     * @return
     */
    List<WesternMedicineVO> list(WesternMedicineVO westernMedicineVO);

    /**
     * 新增西药
     * @param  westernMedicine
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(WesternMedicine  westernMedicine);

    /**
     * 修改西药
     * @param westernMedicine
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(WesternMedicine westernMedicine);

    /**
     * 回显数据，根据id查询中药信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id} and medicine_category_id = 2  " )
    WesternMedicine WesternMedicineSelectUpdateById(Long id);

    /**
     * 根据药品id查询西药信息
     * @param id
     * @return
     */
    @Select("select * from chinese_western_medicine where id = #{id}")
    WesternMedicine WesternMedicineById(Long id);

    /**
     * 根据药品ids集合删除西药信息
     * @param ids
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据中药名称查询西药id
     * @param name
     * @return
     */
    @Select("select id from chinese_western_medicine where name = #{name}")
    Long getIdByWesternMedicineName(String name);

    /**
     * 组合药药品表+中西药表联立，根据组合药id获取中药信息（集合）
     * @param id
     * @return
     */
    @Select("select cwm.* from chinese_western_medicine cwm left join setmedicine_medicine sm on cwm.id = sm.medicine_id where sm.setmedicine_id = #{id}")
    List<WesternMedicine> getWesternMedicineStatusList(Long id);
}
